package com.midou.administration.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.midou.administration.bo.*;
import com.midou.administration.entity.Desk;
import com.midou.administration.entity.DeskType;
import com.midou.administration.entity.DishType;
import com.midou.administration.entity.Menu;
import com.midou.administration.service.impl.DishTypeServiceImpl;
import com.midou.administration.service.impl.MenuServiceImpl;
import com.midou.administration.utils.QRCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.UUID;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author MrChen
 * @since 2021-03-24
 */
@Slf4j
@RestController
@RequestMapping("/administration/menu")
public class MenuController {
    @Autowired
    private MenuServiceImpl menuService;

    private String staticPath = System.getProperty("user.dir")+"\\midou-restaurant-administration\\src\\main\\resources\\static\\image";


    /**
     * 查询全部菜谱
     * @return 菜谱集合
     */
    @ResponseBody
    @RequestMapping("findMenuAll")
    public Page findMenuAll(@RequestBody MenuPagination menuPagination){
        return menuService.findAll(menuPagination);
    }

    @ResponseBody
    @RequestMapping("judgmentMenuName")
    public int judgmentMenuName(@RequestBody String menuName){
        int count = menuService.judgmentMenuName(menuName);
        return count;
    }

    /**
     * 按照id查询菜谱
     * @param id 前台传入的菜谱id
     * @return 查询出的对象
     */
    @ResponseBody
    @RequestMapping("findIdMenu")
    public Menu findIdMenu(@RequestBody int id){
      System.out.println(id);
      Menu menu = menuService.findIdMenu(id);
      return menu;
    }

    /**
     * 编辑单个菜谱
     * @param menu 编辑单个菜谱
     * @return 受影响的行数
     */
    @ResponseBody
    @RequestMapping("updMenuAll")
    public int updMenu(@RequestBody Menu menu){
      int upd = this.menuService.updMenu(menu);
      return upd;
    }

    /**
     * 添加菜谱
     * @param menu 前台传入的数组
     * @return 受影响的行数
     */
    @ResponseBody
    @RequestMapping("istMenu")
    public int istMenu(@RequestBody Menu menu){
      int ist = menuService.istMenu(menu);
      return ist;
    }


    /**
     * 删除菜谱
     * @param id 前台传入菜谱id
     * @return 受影响的行数
     */
    @RequestMapping("delMenu")
    public int delMenu(@RequestBody int id){
      int del = menuService.delMenu(id);
      return del ;
    }

  /**
   * 查询是否为套餐
   *
   */
  @RequestMapping("queryAll")
  public Page query(@RequestBody MenuBofenye menuBofenye){
    return menuService.queryAll(menuBofenye);
  }
  /**
   * 修改套餐前查询
   */
  @RequestMapping("queryId")
  public MenuBo queryId(@RequestBody Integer eid){
    MenuBo m=menuService.queryId(eid);
    return menuService.queryId(eid);
  }
  /**
   * 修改套餐信息
   */
  @RequestMapping("queryUp")
  public int queryUp(@RequestBody MenuBo menuBo){
    int a=menuService.queryUp(menuBo);
    if (a>0){
      return menuService.queryUp(menuBo);
    }else {
      return 0;
    }
  }

  @RequestMapping("updPopulaFalse")
  public int updPopulaFalse(@RequestBody int id){
    int num = menuService.updPopulaFalse(id);
    return num;
  }

  @RequestMapping("updPopulaTrue")
  public int updPopulaTrue(@RequestBody int id){
    int num = menuService.updPopulaTrue(id);
    return num;
  }

  @RequestMapping("updrecommendFalse")
  public int updrecommendFalse(@RequestBody int id){
    int num = menuService.updrecommendFalse(id);
    return num;
  }

  @RequestMapping("updrecommendTrue")
  public int updrecommendTrue(@RequestBody int id){
    int num = menuService.updrecommendTrue(id);
    return num;
  }

  @RequestMapping("upddiscountFalse")
  public int upddiscountFalse(@RequestBody int id){
    int num = menuService.upddiscountFalse(id);
    return num;
  }

  @RequestMapping("upddiscountTrue")
  public int upddiscountTrue(@RequestBody int id){
    int num = menuService.upddiscountTrue(id);
    return num;
  }

  //更新是否上架
  @RequestMapping("updputontheshelfTrue")
  public int updputontheshelfTrue(@RequestBody int id){
    int num = menuService.updputontheshelfTrue(id);
    return num;
  }

  //更新是否上架
  @RequestMapping("updputontheshelfFalse")
  public int updputontheshelfFalse(@RequestBody int id){
    int num = menuService.updputontheshelfFalse(id);
    return num;
  }

  @Autowired
  private DishTypeServiceImpl dishTypeService;


//  @RequestMapping("findlist")
//  public List<DishType> lists(){
//    List<DishType> list=dishTypeService.findAll();
//   return dishTypeService.findAll();
//  }


    /**
     * 根据菜品分类查询菜品信息
     * @param
     * @return
     */
    @RequestMapping("/queryBybusinessAndMenu")
    public List<Menu> query(int dishTypeId){
      return this.menuService.queryBybusinessAndMenu(dishTypeId);
    }

    @RequestMapping("/query-set-meal")
    public Page querySetMeal(@RequestBody QuerySetMealPageBo qsmpb){
        qsmpb.setIfGetMeal(1);
        return menuService.queryAllSetMeal(qsmpb);
    }
    /**
     * 查询单条记录
     */
    @RequestMapping("/query-menu-one")
    public Menu queryMenuOne(@RequestBody Integer mid){
        return menuService.queryMenuOne(mid);
    }

    @RequestMapping("/query-menu")
    public List<Menu> queryMenu(@RequestBody menuGroupIdBo mgb){
        return menuService.queryMenu(mgb);
    }
    @RequestMapping("/query-all-dishes")
    public List<Menu> queryAllMenu(@RequestBody QuerySetMealPageBo qsmpb){
        qsmpb.setIfGetMeal(0);
        qsmpb.setState(1);
        return menuService.queryAllMenu(qsmpb);
    }
    @RequestMapping("/addmenu-and-setmeal")
    public Integer addMenuAndSetMeal(@RequestBody MenuBo mb){
        mb.setDishTypeId(7);
        try{
            Integer count = menuService.addSetMeal(mb);
            return count;
        }catch (Exception e){
            return 0;
        }
    }
    @RequestMapping("/findMenuName")
    public List<Menu> findMenuName(@RequestBody String menuName){
      System.out.println(menuName);
      List<Menu> menu = menuService.findMenuName(menuName);
      return menu;
    }

    @RequestMapping("/group-repeat-verification")
    public Integer groupRepeatVerification(@RequestBody menuGroupIdBo mgb){
        return menuService.groupRepeatVerification(mgb);
    }
    @RequestMapping("/del-menu-in-set-meal")
    public Integer delMenuInSetMeal(@RequestBody Integer mid){
        return menuService.delMenuInSetMeal(mid);
    }
    @RequestMapping("/modify-menu-in-setMeal")
    public Integer modifyMenuInSetMeal(@RequestBody MenuBo mb){
        return menuService.modifyMenuInSetMeal(mb);
    }
    @RequestMapping("/off/shelf")
    public Integer offShelf(@RequestBody CommonResult<Integer> cr){
        return menuService.updateShelf(cr);
    }
    @RequestMapping("/whether/recommend")
    public Integer whetherRecommend(@RequestBody CommonResult<Integer> cr){
        return menuService.whetherRecommend(cr);
    }
}
